package com.drg.center.controller;

import com.drg.center.entity.param.*;
import com.drg.center.entity.result.*;
import com.drg.center.service.DataMiningAnalysisService;
import com.drg.center.service.StatisticsDoctorFromEsService;
import com.guaike.core.entity.result.PageEntity;
import com.guaike.core.entity.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/dataMiningAnalysis")
@Api(tags = "数据挖掘分析接口组")
@AllArgsConstructor
public class DataMiningAnalysisController {

    private final DataMiningAnalysisService dataMiningAnalysisService;
    private final StatisticsDoctorFromEsService statisticsDoctorFromEsService;


    @GetMapping("/dataQualityAnalysis")
    @ApiOperation(value = "数据质量分析")
    public Result<DataQualityVO> dataQualityAnalysis(@Valid DataQualityDTO param) {
        return dataMiningAnalysisService.dataQualityAnalysis(param);
    }

    @GetMapping("/medicalServiceCapability")
    @ApiOperation(value = "医疗服务能力")
    public Result<MedicalServiceCapabilityVO> medicalServiceCapability(@Valid DataQualityDTO param) {
        return dataMiningAnalysisService.medicalServiceCapability(param);
    }

    @GetMapping("/medicalServiceQuality")
    @ApiOperation(value = "医疗服务质量")
    public Result<DataMedicalServerqualityVO> medicalServiceQuality(@Valid DataQualityDTO param) {
        return dataMiningAnalysisService.medicalServiceQuality(param);
    }


    @GetMapping("/departServiceEfficiency")
    @ApiOperation(value = "科室服务效率")
    public Result<List<DepartServiceEfficiencyPageVO>> departServiceEfficiency(@Valid DepartServiceEfficiencyDTO param) {
        return dataMiningAnalysisService.departServiceEfficiency(param);
    }

    @GetMapping("/exportDepartServiceEfficiencyExcel")
    @ApiOperation(value = "导出科室服务效率excel")
    public void exportDepartServiceEfficiencyExcel(HttpServletResponse response, DepartServiceEfficiencyDTO param) throws Exception {
        dataMiningAnalysisService.exportDepartServiceEfficiencyExcel(response, param);
    }

    @GetMapping("/departDieRate")
    @ApiOperation(value = "科室死亡率")
    public Result<List<DepartDieRatePageVO>> departDieRate(@Valid DepartServiceEfficiencyDTO param) {
        return dataMiningAnalysisService.departDieRate(param);
    }

    @GetMapping("/exportDepartDieRateExcel")
    @ApiOperation(value = "导出科室死亡率excel")
    public void exportDepartDieRateExcel(HttpServletResponse response, DepartServiceEfficiencyDTO param) throws Exception {
        dataMiningAnalysisService.exportDepartDieRateExcel(response, param);
    }

    @GetMapping("/medicalInsuranceBenchmarkingAnalysis")
    @ApiOperation(value = "医保标杆值分析列表")
    public Result<List<MedicareBenchmarkingAnalysisPageVO>> medicalInsuranceBenchmarkingAnalysis(@Valid MedicalInsuranceBenchmarkingAnalysisDTO param) {
        return dataMiningAnalysisService.medicalInsuranceBenchmarkingAnalysis(param);
    }

    @GetMapping("/medicalInsuranceBenchmarkingAnalysisExcel")
    @ApiOperation(value = "导出医保标杆值分析excel")
    public void medicalInsuranceBenchmarkingAnalysisExcel(HttpServletResponse response, MedicalInsuranceBenchmarkingAnalysisDTO param) throws Exception {
        dataMiningAnalysisService.medicalInsuranceBenchmarkingAnalysisExcel(response, param);
    }

    @GetMapping("/patientStructuralAnalysis")
    @ApiOperation(value = "患者结构分析")
    public Result<PatientStructuralAnalysisVO> patientStructuralAnalysis(@Valid PatientStructuralAnalysisDTO param) {
        return dataMiningAnalysisService.patientStructuralAnalysis(param);
    }

    @GetMapping("/patientAccessCostsAnalysis")
    @ApiOperation(value = "患者就医成本分析列表")
    public Result<PageEntity<PatientAccessCostsAnalysisPageVO>> patientAccessCostsAnalysis(@Valid PatientAccessCostsAnalysisDTO param) {
        return dataMiningAnalysisService.patientAccessCostsAnalysis(param);
    }

//    @GetMapping("/patientAccessCostsAnalysisExcel")
//    @ApiOperation(value = "导出患者就医成本分析excel")
//    public void patientAccessCostsAnalysisExcel(HttpServletResponse response, PatientAccessCostsAnalysisDTO param) throws Exception {
//        dataMiningAnalysisService.patientAccessCostsAnalysisExcel(response, param);
//    }

    @GetMapping("/fundBudgetUseAnalysis")
    @ApiOperation(value = "基金预算使用分析列表")
    public Result<ChartLineVO> fundBudgetUseAnalysis(@Valid FundBudgetUseAnalysisDTO param) {
        ChartLineVO chartLineVO = statisticsDoctorFromEsService.getExpireFundCostTrend(param.getYear(), param.getDepartCodes());
        return Result.success().data(chartLineVO).build();
    }

    @GetMapping("/comprehensiveAnalysis")
    @ApiOperation(value = "综合分析列表")
    public Result<List<ComprehensiveAnalysisPageVO>> comprehensiveAnalysis(@Valid ComprehensiveAnalysisDTO param) {
        return dataMiningAnalysisService.comprehensiveAnalysis(param);
    }

//    @GetMapping("/comprehensiveAnalysisExcel")
//    @ApiOperation(value = "导出综合分析excel")
//    public void comprehensiveAnalysisExcel(HttpServletResponse response, ComprehensiveAnalysisDTO param) throws Exception {
//        dataMiningAnalysisService.comprehensiveAnalysisExcel(response, param);
//    }

    @GetMapping("/overRankingAnalysis")
    @ApiOperation(value = "超额排名分析列表")
    public Result<List<OverRankingAnalysisPageVO>> overRankingAnalysis(@Valid OverRankingAnalysisDTO param) {
        return dataMiningAnalysisService.overRankingAnalysis(param);
    }

//    @GetMapping("/overRankingAnalysisExcel")
//    @ApiOperation(value = "导出超额排名分析excel")
//    public void overRankingAnalysisExcel(HttpServletResponse response, OverRankingAnalysisDTO param) throws Exception {
//        dataMiningAnalysisService.overRankingAnalysisExcel(response, param);
//    }

    @GetMapping("/auditResultsAnalysis")
    @ApiOperation(value = "审核结果分析列表")
    public Result<PageEntity<AuditResultsAnalysisPageVO>> auditResultsAnalysis(@Valid AuditResultsAnalysisDTO param) {
        return dataMiningAnalysisService.auditResultsAnalysis(param);
    }

    @GetMapping("/singleDiseaseHospitalizationCostAnalysis")
    @ApiOperation(value = "住院单病种费用分析列表")
    public Result<PageEntity<SingleDiseaseHospitalizationCostAnalysisPageVO>> singleDiseaseHospitalizationCostAnalysis(@Valid SingleDiseaseHospitalizationCostAnalysisDTO param) {
        return dataMiningAnalysisService.singleDiseaseHospitalizationCostAnalysis(param);
    }
}
